<?php
namespace app\admin\controller;

use app\common\model\Ilike as IlikeModel;
use app\common\model\Manager as ManagerModel;
use app\common\model\Member as MemberModel;
use app\common\model\ManagerCompany as ManagerCompanyModel;
use app\common\model\Gather as GatherModel;
use app\common\model\BuddhistService as BuddhistServiceModel;

/**
 * 关注寺院控制器
 * Class Ilike
 * @package app\index\controller
 */
class Ilike extends Base
{
    /**
     * [getIndex  查看]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function index()
    {
        $data = input('param.');
        $this->getPageAndSize($data);
        $model = new IlikeModel;
        $mmodel = new ManagerModel;
        $memodel = new MemberModel;
        $mcmodel = new ManagerCompanyModel;
        $gmodel = new GatherModel;
        $bmodel = new BuddhistServiceModel;
        $map = [];
        $map1 = [];
        $user = $this->user;
        try{
            $map['i.status'] = 1;
            $map['i.memid'] = $data['mid'];
            $field = 'c.id,c.comname,c.phone,c.province,c.city,c.qu,c.compic,c.manager_id,c.addtime,c.states';
            $count = $model->getCount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getlist($map,$this->from, $this->size,$field);
            foreach($lists as &$v){
                $v['addtime'] = date('Y-m-d H:i:s',$v['addtime']);
//                $manager = $mmodel->findData($v['manager_id'],'id','tel,username');
//                $v['tel'] = $manager['tel'];
//                $v['fahao'] = $manager['username'];
//                $member = $memodel->findOne(['tel'=>$v['tel']],'username');
//                $v['username'] = $member['username'];
                $v['senlv_num'] = $mcmodel->getAllCount(['comid'=>$v['id'],'status'=>1]);
                $v['xinzhong_num'] = $model->getAllCount(['itemid'=>$v['id'],'status'=>1]);
                $map1['states'] = ['neq',-1];
                $map1['type'] = 1;
                $map1['comid'] = $v['id'];
                $v['shehui_num'] = $gmodel->getAllCount($map1);
                $map1['type'] = 2;
                $v['yigong_num'] = $gmodel->getAllCount($map1);
                $v['buddhist_num'] = $bmodel->getAllCount(['comid'=>$v['id']]);
            }
        }catch(\Exception $e){
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        return admin_json(1,'获取成功',[
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
}